package cn.lingyangwl.agile.pay.pay.controller.payorder;

import cn.lingyangwl.agile.pay.common.annotation.PayCheck;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import cn.lingyangwl.agile.common.security.annotation.Anonymous;
import cn.lingyangwl.agile.pay.model.rqrs.pay.payorder.PayOrderQO;
import cn.lingyangwl.agile.pay.model.rqrs.pay.payorder.PayOrderRS;
import cn.lingyangwl.agile.pay.validation.PaySignGroup;
import cn.lingyangwl.agile.pay.pay.process.payorder.QueryOrderProcess;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 商户查单controller
 */
@Slf4j
@RestController
@Anonymous
public class QueryOrderController {

    @Resource
    private QueryOrderProcess queryOrderProcess;

    /**
     * 查单接口
     */
    @PostMapping("/pay/getOrder")
    @PayCheck
    public Resp<PayOrderRS> getOrder(@RequestBody @Validated(value = PaySignGroup.class) PayOrderQO rq){
        if(StringUtils.isAllEmpty(rq.getMchOrderNo(), rq.getPayOrderNo())){
            throw new BizException("mchOrderNo 和 payOrderNo不能同时为空");
        }
        return queryOrderProcess.getPayOrder(rq);
    }

}
